home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / jungle / jungle.jar / JungleScreen.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-05-16  |  18.9 KB  |  1,159 lines

  1. import java.io.ByteArrayInputStream;
  2. import java.io.ByteArrayOutputStream;
  3. import java.io.DataInputStream;
  4. import java.io.DataOutputStream;
  5. import java.util.Random;
  6. import java.util.Vector;
  7. import javax.microedition.lcdui.Canvas;
  8. import javax.microedition.lcdui.Font;
  9. import javax.microedition.lcdui.Graphics;
  10. import javax.microedition.lcdui.Image;
  11.  
  12. class JungleScreen extends Canvas {
  13.    private static final boolean DEBUG = false;
  14.    private static final int gtl = 20;
  15.    private static final int CONST_levelIncrease = 150;
  16.    private static final int CONST_levelIncreaseHC = 250;
  17.    private int cheatIndex = 0;
  18.    public static boolean cheatEnabled = false;
  19.    private static final int[] cheatCode = new int[]{55, 55, 55, 55, 54, 54, 54, 51, 51, 51, 52, 52, 52, 50};
  20.    private static final int[] cheatCode2 = new int[]{50, 57, 57, 57, 50, 50, 50, 50, 50, 56, 56, 56};
  21.    private int width;
  22.    private int height;
  23.    private int gameMode;
  24.    private int gameTimer;
  25.    private boolean paused = false;
  26.    private Image[] image;
  27.    private Image[] hsImage;
  28.    private Image dbufi;
  29.    private Graphics dbufg;
  30.    private Font font;
  31.    private Font font2;
  32.    private int[] blockFrame;
  33.    private int[][] blockPos;
  34.    private Vector bubble;
  35.    private int playerPos;
  36.    private int playerPosCounter;
  37.    private int playerState;
  38.    private int playerX;
  39.    private int playerY;
  40.    private int playerFrame;
  41.    private boolean playerHasTreasure;
  42.    private int playerGotTreasure = -1;
  43.    private int score;
  44.    private int lives;
  45.    private int spiderX;
  46.    private int spiderY;
  47.    private int spiderState;
  48.    private int spiderPos;
  49.    private int stompState;
  50.    private int stompPos;
  51.    private int stompYPos;
  52.    private int rightRockY;
  53.    private int boxState;
  54.    private int boxCounter;
  55.    private int treasureType;
  56.    private int treasureWas;
  57.    private int numBlocks = 4;
  58.    private int blockLimit1;
  59.    private int blockLimit2;
  60.    private int blockLimit3;
  61.    private int bubbleDensity;
  62.    private int spiderStaysStill;
  63.    private final int _easyBlockLimit1 = 18;
  64.    private final int _easyBlockLimit2 = 25;
  65.    private final int _easyBlockLimit3 = 30;
  66.    private final int _easyBubbleDensity = 20;
  67.    private final int _easySpiderStaysStill = 50;
  68.    private final int _hardBlockLimit1 = 10;
  69.    private final int _hardBlockLimit2 = 15;
  70.    private final int _hardBlockLimit3 = 20;
  71.    private final int _hardBubbleDensity = 10;
  72.    private final int _hardSpiderStaysStill = 20;
  73.    private boolean notifyFromMenu = false;
  74.    private Runko runko;
  75.    private int levelIncrease;
  76.    private int gLevel = 0;
  77.    private boolean restart;
  78.    private String[][] hsName = new String[3][10];
  79.    private int[][] hsValue = new int[3][10];
  80.    private static final String[] resource = new String[]{"logo", "hero", "blokit", "tasot", "txt_vesi", "intro", "info", "stomp"};
  81.    private static Random rnd0 = new Random(System.currentTimeMillis());
  82.    private long startsctm;
  83.    private long Gsctm;
  84.    private boolean tunnariPlayed = false;
  85.  
  86.    private static int random() {
  87.       return rnd0.nextInt() >>> 1;
  88.    }
  89.  
  90.    public void mode(int var1, int var2) {
  91.       this.gameMode = var1;
  92.       this.gameTimer = var2;
  93.       this.playerGotTreasure = -1;
  94.    }
  95.  
  96.    public JungleScreen(Runko var1) {
  97.       this.runko = var1;
  98.    }
  99.  
  100.    public Image[] getPics() {
  101.       return this.hsImage;
  102.    }
  103.  
  104.    public void hideNotify() {
  105.       this.paused = true;
  106.       if (!this.notifyFromMenu) {
  107.          this.runko.showMenu(this);
  108.       }
  109.  
  110.    }
  111.  
  112.    public void showNotify() {
  113.       this.paused = false;
  114.       this.notifyFromMenu = false;
  115.    }
  116.  
  117.    public void exit() {
  118.       this.restart = true;
  119.    }
  120.  
  121.    public void init() {
  122.       this.width = 96;
  123.       this.height = 65;
  124.       this.dbufi = Image.createImage(this.width, this.height);
  125.       this.dbufg = this.dbufi.getGraphics();
  126.       this.font = Font.getFont(64, 1, 8);
  127.       this.font2 = Font.getFont(64, 0, 8);
  128.       Runko.setProgressMax(resource.length + 2);
  129.       this.image = new Image[resource.length];
  130.  
  131.       for(int var1 = 0; var1 < resource.length; ++var1) {
  132.          try {
  133.             this.image[var1] = Jil.loadImage(resource[var1]);
  134.             Runko.addProgress();
  135.          } catch (Exception var4) {
  136.             ((Throwable)var4).printStackTrace();
  137.          }
  138.       }
  139.  
  140.       for(int var2 = 0; var2 < 10; ++var2) {
  141.          this.hsName[0][var2] = this.hsName[1][var2] = this.hsName[2][var2] = "MrG";
  142.          this.hsValue[0][var2] = this.hsValue[1][var2] = this.hsValue[2][var2] = 0;
  143.       }
  144.  
  145.       this.loadHighScores();
  146.       Runko.addProgress();
  147.       this.hsImage = new Image[3];
  148.  
  149.       for(int var3 = 0; var3 < 3; ++var3) {
  150.          this.hsImage[var3] = Image.createImage(this.width, 26 + this.font2.getHeight() * 10);
  151.          this.updateHighScoreImage(this.hsImage[var3], var3, this.hsName[var3], this.hsValue[var3]);
  152.       }
  153.  
  154.       MelodyManager.loadMelody(this.getClass().getResourceAsStream("sound.dat"), 203);
  155.       Runko.addProgress();
  156.       this.mode(42, 0);
  157.       this.newGame();
  158.       System.gc();
  159.    }
  160.  
  161.    protected synchronized void paint(Graphics var1) {
  162.       this.dbufg.setColor(16777215);
  163.       this.dbufg.setClip(0, 0, this.width, this.height);
  164.       this.dbufg.fillRect(0, 0, this.width, this.height);
  165.       switch (this.gameMode) {
  166.          case 0:
  167.          case 5:
  168.          case 69:
  169.             Jil.drawSubImage(this.image[4], 0, 0, 101, 30, this.dbufg, (this.width >> 1) - 50, 0);
  170.             int var12 = this.boxState == 1 ? 1 : 0;
  171.             Jil.drawSubImage(this.image[2], 22 + var12 * 10, 38, 10, 14, this.dbufg, this.width - 10 + 3, 26 - (40 - this.rightRockY));
  172.             this.drawSubImage(this.image[2], 11, 38, 11, 15, this.dbufg, -3, 40);
  173.             this.drawSubImage(this.image[2], 0, 38, 11, 15, this.dbufg, this.width - 8, this.rightRockY);
  174.  
  175.             for(int var5 = -1; var5 < (this.width >> 4) + 2; ++var5) {
  176.                this.drawSubImage(this.image[4], 65, 68, 16, 6, this.dbufg, var5 * 16 - this.gameTimer % 16, this.height - 15);
  177.             }
  178.  
  179.             for(int var6 = 0; var6 < this.numBlocks; ++var6) {
  180.                Jil.drawSubImage(this.image[3], 0, 12 * this.blockFrame[var6], 12, 12, this.dbufg, this.blockPos[var6][0] - 3, this.blockPos[var6][1]);
  181.             }
  182.  
  183.             if (this.spiderState != 8 && this.spiderState != 9 && this.spiderState != 1 && this.spiderState != 2) {
  184.                int var13 = this.gameTimer % 3 < 2 ? 0 : 1;
  185.                Jil.drawSubImage(this.image[2], 0 + var13 * 18, 53, 18, 18, this.dbufg, this.spiderX + var13 - 3, this.spiderY);
  186.             } else {
  187.                Jil.drawSubImage(this.image[2], 36, 54, 15, 16, this.dbufg, this.spiderX - 3, this.spiderY + 2);
  188.  
  189.                for(int var7 = 0; var7 < (this.spiderY >> 2) + 1; ++var7) {
  190.                   Jil.drawSubImage(this.image[2], 31, 71, 2, 4, this.dbufg, this.spiderX - 3 + 6, var7 * 4);
  191.                }
  192.             }
  193.  
  194.             if (this.playerGotTreasure > -1 && this.gameTimer - this.playerGotTreasure < 10) {
  195.                int var14 = 12 - (this.gameTimer - this.playerGotTreasure) * 4;
  196.                if (var14 < 0) {
  197.                   var14 = -var14;
  198.                }
  199.  
  200.                this.drawSubImage(this.image[3], 0, 96 + 11 * this.treasureType, 12, 11, this.dbufg, this.width - 10, var14);
  201.             } else if (this.boxState == 1) {
  202.                this.drawSubImage(this.image[3], 0, 96 + 11 * this.treasureType, 12, 11, this.dbufg, this.width - 10 + 2, 20);
  203.             }
  204.  
  205.             this.drawSubImage(this.image[1], 0, 17 * this.playerFrame, 15, 17, this.dbufg, this.playerX - 3, this.playerY - 2);
  206.             if (this.stompState != 0) {
  207.                this.drawSubImage(this.image[7], 0, 0, this.image[7].getWidth(), this.image[7].getHeight(), this.dbufg, this.blockPos[this.stompPos][0] - 3 - 1, this.stompYPos);
  208.             }
  209.  
  210.             for(int var15 = -1; var15 < this.width / 10 + 2; ++var15) {
  211.                this.drawSubImage(this.image[4], 81, 68, 10, 9, this.dbufg, var15 * 10 + this.gameTimer % 10, this.height - 8);
  212.             }
  213.  
  214.             for(int var8 = 0; var8 < this.bubble.size(); ++var8) {
  215.                JungleScreen$Bubble var9 = (JungleScreen$Bubble)this.bubble.elementAt(var8);
  216.                if (var9.y < this.height - 9) {
  217.                   if (var9.frame != 0 && var9.frame != 1) {
  218.                      this.drawSubImage(this.image[2], 8 + (var9.frame - 2) * 15, 71, var9.frame == 2 ? 8 : 7, 8, this.dbufg, var9.x - 3, var9.y);
  219.                   } else {
  220.                      this.drawSubImage(this.image[2], var9.frame * 16, 71, var9.frame == 0 ? 8 : 7, 8, this.dbufg, var9.x - 3, var9.y);
  221.                   }
  222.                }
  223.             }
  224.  
  225.             if (this.playerState == 0 && this.playerGotTreasure > -24 && this.playerGotTreasure < 0 && this.score != 0) {
  226.                this.drawSubImage(this.image[3], 0, 129 + 11 * this.treasureWas, 12, 11, this.dbufg, 0, 14 + (this.playerGotTreasure -= 2));
  227.             }
  228.  
  229.             if (this.playerHasTreasure) {
  230.                Jil.drawSubImage(this.image[3], 0, 96 + 11 * this.treasureType, 12, 11, this.dbufg, 3, this.height - 11 - 3);
  231.             }
  232.  
  233.             if (!cheatEnabled) {
  234.                for(int var16 = this.lives; var16 > 0; --var16) {
  235.                   Jil.drawSubImage(this.image[2], 34, 71, 7, 7, this.dbufg, this.width - 20 + var16 * 4, this.height - 8);
  236.                }
  237.             }
  238.  
  239.             if (this.gameMode == 5) {
  240.                if (this.gameTimer < 9) {
  241.                   this.drawSubImage(this.image[4], 0, 69, 64, 11, this.dbufg, (this.width >> 1) - 32, -12 + this.gameTimer * 4);
  242.                } else {
  243.                   Jil.drawSubImage(this.image[4], 0, 69, 64, 11, this.dbufg, (this.width >> 1) - 32, 26);
  244.                }
  245.             }
  246.  
  247.             if (this.gameMode == 69) {
  248.                Jil.drawSubImage(this.image[4], 57, 81, 40, 15, this.dbufg, (this.width >> 1) - 20, 16);
  249.             }
  250.  
  251.             this.dbufg.setClip(0, 0, this.width, this.height);
  252.             if (this.gameMode == 69 && this.gameTimer % 10 >= 5) {
  253.                this.dbufg.setColor(0);
  254.                this.dbufg.drawString("Press any key", (this.width >> 1) - (this.font.stringWidth("Press any key") >> 1) + 1, 30, 20);
  255.             }
  256.  
  257.             this.dbufg.setColor(0);
  258.             this.dbufg.setFont(this.font);
  259.             this.dbufg.drawString("Score: " + String.valueOf(this.score), (this.width >> 1) - (this.font.stringWidth("Score: " + String.valueOf(this.score)) >> 1), this.height - this.font.getHeight(), 20);
  260.             break;
  261.          case 42:
  262.          case 50:
  263.             if (this.gameMode == 42) {
  264.                this.dbufg.setClip(0, 0, this.width, this.height);
  265.                this.dbufg.drawImage(this.image[0], (this.width >> 1) - (this.image[0].getWidth() >> 1) - 2, 0, 20);
  266.                ++this.gameTimer;
  267.             } else {
  268.                this.dbufg.setClip(0, 0, this.width, this.height);
  269.                this.dbufg.drawImage(this.image[6], (this.width >> 1) - (this.image[6].getWidth() >> 1), -4, 20);
  270.                Jil.drawSubImage(this.image[2], 0, 0, 52, 30, this.dbufg, (this.width >> 1) - 26, this.image[6].getHeight() - 10);
  271.                Jil.drawSubImage(this.image[2], 6, 33, 40, 5, this.dbufg, (this.width >> 1) - 20, this.gLevel == 0 ? this.image[6].getHeight() - 3 : this.image[6].getHeight() + 7);
  272.                this.dbufg.setClip(0, 0, this.width, this.height);
  273.                this.dbufg.setColor(0);
  274.                Font var4;
  275.                if (this.gLevel == 0) {
  276.                   var4 = this.font;
  277.                } else {
  278.                   var4 = this.font2;
  279.                }
  280.  
  281.                this.dbufg.setFont(var4);
  282.                this.dbufg.drawString("easy", (this.width >> 1) - (var4.stringWidth("easy") >> 1), this.image[6].getHeight() - 5, 20);
  283.                if (this.gLevel == 1) {
  284.                   var4 = this.font;
  285.                } else {
  286.                   var4 = this.font2;
  287.                }
  288.  
  289.                this.dbufg.setFont(var4);
  290.                this.dbufg.drawString("hard", (this.width >> 1) - (var4.stringWidth("hard") >> 1), this.image[6].getHeight() + 5, 20);
  291.             }
  292.             break;
  293.          case 49:
  294.             this.dbufg.drawImage(this.image[5], (this.width >> 1) - (this.image[5].getWidth() >> 1), 0, 20);
  295.             Jil.drawSubImage(this.image[2], 0, 0, 52, 30, this.dbufg, (this.width >> 1) - 26, this.image[5].getHeight() + 2);
  296.             Jil.drawSubImage(this.image[2], 6, 33, 40, 5, this.dbufg, (this.width >> 1) - 20, this.gLevel == 0 ? this.image[5].getHeight() + 9 : this.image[5].getHeight() + 19);
  297.             this.dbufg.setClip(0, 0, this.width, this.height);
  298.             this.dbufg.setColor(0);
  299.             Font var3;
  300.             if (this.gLevel == 0) {
  301.                var3 = this.font;
  302.             } else {
  303.                var3 = this.font2;
  304.             }
  305.  
  306.             this.dbufg.setFont(var3);
  307.             this.dbufg.drawString("start", (this.width >> 1) - (var3.stringWidth("start") >> 1), this.image[5].getHeight() + 8, 20);
  308.             if (this.gLevel == 1) {
  309.                var3 = this.font;
  310.             } else {
  311.                var3 = this.font2;
  312.             }
  313.  
  314.             this.dbufg.setFont(var3);
  315.             this.dbufg.drawString("help", (this.width >> 1) - (var3.stringWidth("help") >> 1), this.image[5].getHeight() + 18, 20);
  316.             break;
  317.          case 51:
  318.             this.dbufg.setFont(this.font2);
  319.             this.dbufg.setColor(0);
  320.             int var2 = (int)((System.currentTimeMillis() - this.startsctm << 8) / 3000L * (long)(((Canvas)this).getHeight() + 10)) >> 8;
  321.             this.dbufg.drawString("all your base", ((Canvas)this).getWidth() >> 1, var2, 17);
  322.             this.dbufg.drawString("are belong to us!", ((Canvas)this).getWidth() >> 1, var2 + this.font2.getHeight(), 17);
  323.             break;
  324.          case 99:
  325.             this.dbufg.setFont(this.font2);
  326.             this.dbufg.setColor(0);
  327.             this.dbufg.drawString("saving high scores", (((Canvas)this).getWidth() >> 1) - (this.font2.stringWidth("saving high scores") >> 1), (((Canvas)this).getHeight() >> 1) - this.font2.getHeight(), 20);
  328.             this.dbufg.drawString("please wait...", (((Canvas)this).getWidth() >> 1) - (this.font2.stringWidth("please wait...") >> 1), (((Canvas)this).getHeight() >> 1) + this.font2.getHeight(), 20);
  329.       }
  330.  
  331.       var1.drawImage(this.dbufi, (((Canvas)this).getWidth() >> 1) - (this.width >> 1), (((Canvas)this).getHeight() >> 1) - (this.height >> 1), 20);
  332.    }
  333.  
  334.    public int run() {
  335.       if (this.gameMode == 42) {
  336.          this.newGame();
  337.          this.mode(49, 0);
  338.          this.gLevel = 0;
  339.       }
  340.  
  341.       this.restart = false;
  342.       this.gameTimer = 0;
  343.  
  344.       while(this.gameMode != 123 && !this.restart) {
  345.          while(this.paused) {
  346.             try {
  347.                Thread.sleep(500L);
  348.             } catch (InterruptedException var2) {
  349.             }
  350.          }
  351.  
  352.          switch (this.gameMode) {
  353.             case 0:
  354.             case 5:
  355.                this.updatePlayer();
  356.                this.updateRock();
  357.                this.updateBlocks();
  358.                this.updateBubbles();
  359.                this.updateBox();
  360.                this.updateSpider();
  361.                this.updateStomp();
  362.             case 49:
  363.             case 50:
  364.             default:
  365.                break;
  366.             case 69:
  367.                this.updateBox();
  368.          }
  369.  
  370.          ((Canvas)this).repaint();
  371.          ((Canvas)this).serviceRepaints();
  372.          ++this.gameTimer;
  373.          if (!cheatEnabled && this.gameTimer % 150 == 149) {
  374.             ++this.levelIncrease;
  375.          } else if (cheatEnabled && this.gameTimer % 250 == 249) {
  376.             ++this.levelIncrease;
  377.          }
  378.  
  379.          Jil.setBacklight(true);
  380.          Thread.yield();
  381.          if (this.gameMode == 5 && System.currentTimeMillis() - this.Gsctm > 4000L) {
  382.             this.mode(123, 0);
  383.          }
  384.       }
  385.  
  386.       if (!this.restart && this.checkHighScore(this.score) > -1) {
  387.          this.notifyFromMenu = true;
  388.          this.updateHighScore(this.score, this.runko.getName("New high score!", "Enter your name:"));
  389.          if (cheatEnabled) {
  390.             this.updateHighScoreImage(this.hsImage[2], 2, this.hsName[2], this.hsValue[2]);
  391.          } else {
  392.             this.updateHighScoreImage(this.hsImage[this.gLevel], this.gLevel, this.hsName[this.gLevel], this.hsValue[this.gLevel]);
  393.          }
  394.  
  395.          this.mode(99, 0);
  396.          ((Canvas)this).repaint();
  397.          ((Canvas)this).serviceRepaints();
  398.          Thread.yield();
  399.          this.saveHighScores();
  400.       }
  401.  
  402.       this.notifyFromMenu = true;
  403.       this.newGame();
  404.       if (this.restart) {
  405.          this.newGame();
  406.          this.mode(69, 0);
  407.          return -1;
  408.       } else {
  409.          this.mode(42, 0);
  410.          return cheatEnabled ? 2 : this.gLevel;
  411.       }
  412.    }
  413.  
  414.    private void updatePlayer() {
  415.       switch (this.playerState) {
  416.          case 0:
  417.             if (this.numBlocks == 4) {
  418.                this.playerX = this.playerPos * 19;
  419.             } else {
  420.                this.playerX = this.playerPos * 13;
  421.             }
  422.  
  423.             switch (this.playerFrame) {
  424.                case 0:
  425.                   this.playerX -= 5;
  426.                   break;
  427.                case 1:
  428.                   this.playerX -= 4;
  429.                   break;
  430.                case 2:
  431.                   this.playerX -= 5;
  432.                   break;
  433.                case 3:
  434.                   this.playerX -= 3;
  435.                   break;
  436.                case 4:
  437.                   this.playerX -= 5;
  438.                   break;
  439.                case 5:
  440.                   this.playerX -= 3;
  441.             }
  442.  
  443.             if (this.playerPos == 0) {
  444.                this.playerY = 25;
  445.             } else if (this.playerPos == this.numBlocks + 1) {
  446.                this.playerY = 25 - (40 - this.rightRockY);
  447.             } else {
  448.                this.playerY = 27;
  449.             }
  450.  
  451.             ++this.playerPosCounter;
  452.             if (this.playerPos > 0 && this.playerPos < this.numBlocks + 1) {
  453.                if (this.blockFrame[this.playerPos - 1] > 0) {
  454.                   this.playerState = 1;
  455.                }
  456.             } else if (this.playerPos == this.numBlocks + 1 && this.boxState == 1) {
  457.                this.playerHasTreasure = true;
  458.                this.playerGotTreasure = this.gameTimer;
  459.                this.boxState = 2;
  460.                this.score += 5;
  461.             } else if (this.playerPos == 0 && this.playerHasTreasure) {
  462.                this.playerHasTreasure = false;
  463.                this.playerGotTreasure = -1;
  464.                this.boxState = 0;
  465.                if (!cheatEnabled) {
  466.                   switch (this.treasureType) {
  467.                      case 0:
  468.                         this.score += 10;
  469.                         break;
  470.                      case 1:
  471.                         this.score += 25;
  472.                         break;
  473.                      case 2:
  474.                         this.score += 100;
  475.                   }
  476.                } else {
  477.                   this.score += 5;
  478.                }
  479.  
  480.                this.treasureWas = this.treasureType;
  481.                this.treasureType = -1;
  482.                if (Runko.SoundOn) {
  483.                   MelodyManager.playMelody(4);
  484.                }
  485.             }
  486.             break;
  487.          case 1:
  488.             this.playerY += 3;
  489.             if (this.playerY > 70 && this.gameMode != 5) {
  490.                --this.lives;
  491.                if (this.lives > 0 && !cheatEnabled) {
  492.                   this.resetStuff();
  493.                   this.mode(69, 0);
  494.                } else {
  495.                   this.Gsctm = System.currentTimeMillis();
  496.                   if (Runko.SoundOn) {
  497.                      MelodyManager.playMelody(1);
  498.                   }
  499.  
  500.                   this.mode(5, 0);
  501.                }
  502.             }
  503.  
  504.             if (this.playerY < 40) {
  505.                this.playerFrame = 6;
  506.             } else {
  507.                this.playerFrame = 7 + this.gameTimer % 2;
  508.             }
  509.       }
  510.  
  511.    }
  512.  
  513.    private void updateRock() {
  514.       if (this.playerPos == this.numBlocks + 1 && this.playerPosCounter > 25) {
  515.          if (this.playerPosCounter > 50) {
  516.             this.keyPressed(52);
  517.             this.rightRockY = 40;
  518.          } else if (this.playerPosCounter > 40) {
  519.             this.rightRockY += -3 + random() % 7;
  520.             Jil.triggerVibrator(50);
  521.          } else {
  522.             this.rightRockY += -2 + random() % 5;
  523.             Jil.triggerVibrator(35);
  524.          }
  525.  
  526.          this.updatePlayer();
  527.       } else {
  528.          this.rightRockY = 40;
  529.       }
  530.  
  531.    }
  532.  
  533.    private void updateBlocks() {
  534.       int var1;
  535.       int var2;
  536.       int var3;
  537.       if (!cheatEnabled) {
  538.          var1 = this.blockLimit1 - (this.levelIncrease >> 1);
  539.          var2 = this.blockLimit2 - (this.levelIncrease >> 1);
  540.          var3 = this.blockLimit3 - (this.levelIncrease >> 1);
  541.       } else {
  542.          var1 = this.blockLimit1 - this.levelIncrease;
  543.          var2 = this.blockLimit2 - this.levelIncrease;
  544.          var3 = this.blockLimit3 - this.levelIncrease;
  545.       }
  546.  
  547.       if (var1 < 3) {
  548.          var1 = 3;
  549.       }
  550.  
  551.       if (var2 < 5) {
  552.          var2 = 5;
  553.       }
  554.  
  555.       if (var3 < 7) {
  556.          var3 = 7;
  557.       }
  558.  
  559.       for(int var4 = 0; var4 < this.numBlocks; ++var4) {
  560.          if (this.blockFrame[var4] != 0) {
  561.             int var10002 = this.blockFrame[var4]++;
  562.             if (this.blockFrame[var4] >= 8) {
  563.                this.blockFrame[var4] = 0;
  564.             }
  565.          }
  566.  
  567.          if (this.blockPos[var4][1] >= 40) {
  568.             int[] var10000 = this.blockPos[var4];
  569.             var10000[1] += 3;
  570.          } else if (this.playerPos - 1 == var4) {
  571.             if (this.playerPosCounter > var1) {
  572.                if (this.playerPosCounter < var2) {
  573.                   Jil.triggerVibrator(35);
  574.                } else if (this.playerPosCounter <= var3) {
  575.                   Jil.triggerVibrator(50);
  576.                }
  577.  
  578.                this.blockPos[var4][0] = this.getBlockPos(var4) - 1 + random() % 3;
  579.                if (this.playerPosCounter > var2) {
  580.                   this.blockPos[var4][1] = 37 + random() % 3;
  581.                   if (this.playerPosCounter > var3) {
  582.                      this.blockPos[var4][0] = this.getBlockPos(var4);
  583.                      this.blockPos[var4][1] = 40;
  584.                      this.playerState = 1;
  585.                   }
  586.                }
  587.             }
  588.          } else {
  589.             this.blockPos[var4][0] = this.getBlockPos(var4);
  590.             this.blockPos[var4][1] = 38;
  591.          }
  592.       }
  593.  
  594.    }
  595.  
  596.    private void updateBubbles() {
  597.       for(int var1 = 0; var1 < this.bubble.size(); ++var1) {
  598.          JungleScreen$Bubble var2 = (JungleScreen$Bubble)this.bubble.elementAt(var1);
  599.          var2.update();
  600.          if (var2.y <= 46 && var2.counter < 1) {
  601.             if (var2.frame < 2) {
  602.                var2.frame += 2;
  603.             }
  604.  
  605.             ++var2.y;
  606.             ++var2.counter;
  607.          } else if (var2.y <= 46) {
  608.             this.bubble.removeElementAt(var1);
  609.             --var1;
  610.             int var3 = 0;
  611.  
  612.             for(int var4 = 0; var4 < this.numBlocks; ++var4) {
  613.                if (var2.x <= this.getBlockPos(var4) + 3) {
  614.                   var3 = var4;
  615.                   break;
  616.                }
  617.             }
  618.  
  619.             if (this.blockFrame[var3] == 0) {
  620.                this.blockFrame[var3] = 1;
  621.                if (Runko.SoundOn && this.gameMode != 5) {
  622.                   MelodyManager.playMelody(2);
  623.                }
  624.             }
  625.          }
  626.       }
  627.  
  628.       int var5 = this.bubbleDensity - (this.levelIncrease >> 1);
  629.       if (var5 < 2) {
  630.          var5 = 2;
  631.       }
  632.  
  633.       if (random() % var5 == 0) {
  634.          JungleScreen$Bubble var6 = new JungleScreen$Bubble(this, this.getBubbleRandom(), this.height, random() % 2, 0);
  635.          this.bubble.addElement(var6);
  636.       }
  637.  
  638.    }
  639.  
  640.    private void updateBox() {
  641.       if (!cheatEnabled && this.gLevel == 0 && this.levelIncrease < 1 && this.boxState == 0) {
  642.          this.boxState = 1;
  643.          if (this.gameMode != 5) {
  644.             MelodyManager.playMelody(3);
  645.          }
  646.  
  647.          this.treasureType = 0;
  648.       } else if (this.boxState != 2 && this.playerPos != this.numBlocks + 1 && this.boxCounter > 10 && (this.levelIncrease >= 1 || cheatEnabled) && random() % 20 == 0) {
  649.          this.boxState = 1 - this.boxState;
  650.          if (this.boxState == 1) {
  651.             if (this.gameMode != 5) {
  652.                MelodyManager.playMelody(3);
  653.             }
  654.  
  655.             if (this.treasureType == -1) {
  656.                if (!cheatEnabled) {
  657.                   int var1 = random() % 32;
  658.                   if (var1 < 4 && this.levelIncrease > 5) {
  659.                      this.treasureType = 2;
  660.                   } else if (var1 < 12 && this.levelIncrease > 3) {
  661.                      this.treasureType = 1;
  662.                   } else {
  663.                      this.treasureType = 0;
  664.                   }
  665.                } else {
  666.                   this.treasureType = 0;
  667.                }
  668.             }
  669.          }
  670.  
  671.          this.boxCounter = 0;
  672.       }
  673.  
  674.       ++this.boxCounter;
  675.    }
  676.  
  677.    private void updateSpider() {
  678.       if (this.levelIncrease >= 3 || cheatEnabled) {
  679.          byte var1 = 16;
  680.          byte var2 = 73;
  681.          if (this.numBlocks == 6) {
  682.             var1 = 12;
  683.             var2 = 77;
  684.          }
  685.  
  686.          if (this.spiderState == 1) {
  687.             if (this.spiderY > 10) {
  688.                if (this.playerPos == 0) {
  689.                   this.playerState = 1;
  690.                }
  691.  
  692.                this.spiderState = 2;
  693.             } else {
  694.                this.spiderY += 4;
  695.             }
  696.  
  697.          } else if (this.spiderState == 2) {
  698.             if (this.spiderY <= 0) {
  699.                this.spiderY = 0;
  700.                this.spiderState = 0;
  701.                this.spiderPos = 1;
  702.             } else {
  703.                this.spiderY -= 2;
  704.             }
  705.  
  706.          } else {
  707.             if (this.spiderState == 3) {
  708.                if (this.spiderX > 0) {
  709.                   this.spiderX -= 5;
  710.                   if (this.spiderX < 0) {
  711.                      this.spiderX = 0;
  712.                   }
  713.  
  714.                   return;
  715.                }
  716.  
  717.                if (this.spiderX <= 0) {
  718.                   this.spiderPos = 100;
  719.                }
  720.             } else if (this.spiderState == 8 || this.spiderState == 9) {
  721.                if (this.spiderState == 8) {
  722.                   if (this.spiderY > 20) {
  723.                      this.spiderState = 9;
  724.                   } else {
  725.                      this.spiderY += 3;
  726.                   }
  727.                } else if (this.spiderY <= 0) {
  728.                   this.spiderY = 0;
  729.                   this.spiderState = 0;
  730.                   int var3 = this.spiderStaysStill - this.levelIncrease * 4;
  731.                   if (var3 < 1) {
  732.                      var3 = 1;
  733.                   }
  734.  
  735.                   this.spiderPos = 102 + random() % var3;
  736.                } else {
  737.                   this.spiderY -= 2;
  738.                   if (this.spiderY < 0) {
  739.                      this.spiderY = 0;
  740.                   }
  741.                }
  742.  
  743.                if (this.spiderY > 10 && (this.spiderX == this.getBlockPos(this.playerPos - 1) || this.spiderX + 1 == this.getBlockPos(this.playerPos - 1))) {
  744.                   this.spiderState = 9;
  745.                   this.playerState = 1;
  746.                }
  747.  
  748.                return;
  749.             }
  750.  
  751.             if (this.spiderPos <= 100 && this.spiderPos >= 80) {
  752.                if (this.spiderX <= 0 && this.spiderPos != 1) {
  753.                   this.spiderState = 1;
  754.                } else if (this.playerPos == 0 && this.spiderX >= 0) {
  755.                   this.spiderState = 3;
  756.                } else if (this.spiderX <= var1) {
  757.                   this.spiderPos = 1;
  758.                } else if (this.spiderX >= var2) {
  759.                   this.spiderPos = 0;
  760.                } else {
  761.                   this.spiderPos = random() % 2;
  762.                }
  763.             }
  764.  
  765.             if (this.spiderPos == 0 && this.spiderX > var1) {
  766.                this.spiderX -= 2;
  767.             } else if (this.spiderPos == 1 && this.spiderX < var2) {
  768.                this.spiderX += 2;
  769.             } else if (this.spiderX <= var1 && this.playerPos == 0) {
  770.                this.spiderPos = 1;
  771.             }
  772.  
  773.             for(int var4 = 0; var4 < this.numBlocks; ++var4) {
  774.                if ((this.spiderX == this.getBlockPos(var4) || this.spiderX + 1 == this.getBlockPos(var4)) && random() % 20 < 8 && this.spiderPos < 100 && this.spiderState != 3) {
  775.                   if (this.gameMode != 5) {
  776.                      MelodyManager.playMelody(5);
  777.                   }
  778.  
  779.                   this.spiderState = 8;
  780.                }
  781.             }
  782.  
  783.             if (this.spiderPos > 100) {
  784.                --this.spiderPos;
  785.             }
  786.  
  787.             if (this.spiderX < 0) {
  788.                this.spiderX = 0;
  789.             } else if (this.spiderX > var2) {
  790.                this.spiderX = var2;
  791.             }
  792.  
  793.          }
  794.       }
  795.    }
  796.  
  797.    private void updateStomp() {
  798.       if (this.stompState == 0 && this.treasureType == 2 && this.boxState == 2) {
  799.          if (random() % 15 == 0) {
  800.             this.stompState = 1;
  801.             this.stompPos = random() % 3;
  802.             this.stompYPos = -40;
  803.          }
  804.       } else if (this.stompState == 1) {
  805.          this.stompYPos += 5;
  806.          if (this.stompYPos > 0) {
  807.             this.stompYPos = 0;
  808.             this.stompState = 2;
  809.          }
  810.       } else if (this.stompState == 2) {
  811.          this.stompYPos -= 2;
  812.          if (this.stompYPos < -40) {
  813.             this.stompState = 0;
  814.          }
  815.       }
  816.  
  817.       if (this.stompYPos > -13 && (this.stompPos == this.playerPos - 1 || this.stompPos + 1 == this.playerPos - 1)) {
  818.          this.playerState = 1;
  819.       }
  820.  
  821.    }
  822.  
  823.    private void newGame() {
  824.       this.resetStuff();
  825.       this.score = 0;
  826.       this.lives = 3;
  827.       if (this.gLevel != 0 && cheatEnabled) {
  828.          this.blockLimit1 = 10;
  829.          this.blockLimit2 = 15;
  830.          this.blockLimit3 = 20;
  831.          this.bubbleDensity = 10;
  832.          this.spiderStaysStill = 20;
  833.       } else {
  834.          this.blockLimit1 = 18;
  835.          this.blockLimit2 = 25;
  836.          this.blockLimit3 = 30;
  837.          this.bubbleDensity = 20;
  838.          this.spiderStaysStill = 50;
  839.       }
  840.  
  841.       if (this.gLevel != 0 && !cheatEnabled) {
  842.          this.levelIncrease = 4;
  843.       } else {
  844.          this.levelIncrease = 0;
  845.       }
  846.  
  847.       System.gc();
  848.    }
  849.  
  850.    private void resetStuff() {
  851.       this.playerPos = this.playerState = 0;
  852.       this.playerX = -3;
  853.       this.playerY = 25;
  854.       this.playerFrame = 3 + random() % 3;
  855.       this.playerHasTreasure = false;
  856.       this.playerGotTreasure = -1;
  857.       this.boxState = 0;
  858.       this.boxCounter = 0;
  859.       this.treasureType = -1;
  860.       this.treasureWas = -777;
  861.       this.spiderX = 80;
  862.       this.spiderY = 0;
  863.       this.spiderState = this.spiderPos = 0;
  864.       this.stompState = 0;
  865.       this.stompYPos = -40;
  866.       this.rightRockY = 40;
  867.       this.blockFrame = new int[this.numBlocks];
  868.       this.blockPos = new int[this.numBlocks][2];
  869.  
  870.       for(int var1 = 0; var1 < this.numBlocks; ++var1) {
  871.          this.blockPos[var1][0] = this.getBlockPos(var1);
  872.          this.blockPos[var1][1] = 38;
  873.          this.blockFrame[var1] = 0;
  874.       }
  875.  
  876.       this.bubble = new Vector();
  877.    }
  878.  
  879.    private int getBlockPos(int var1) {
  880.       return this.numBlocks == 4 ? 16 + var1 * 19 : 12 + var1 * 13;
  881.    }
  882.  
  883.    private int getBubbleRandom() {
  884.       return this.numBlocks == 4 ? 19 + random() % 4 * 19 : 15 + random() % 6 * 13;
  885.    }
  886.  
  887.    protected void keyPressed(int var1) {
  888.       if (Jil.isMenuKey(var1)) {
  889.          this.paused = true;
  890.          this.notifyFromMenu = true;
  891.          this.runko.showMenu(this);
  892.       } else {
  893.          if (this.gameMode == 69) {
  894.             this.mode(0, 0);
  895.             ((Canvas)this).repaint();
  896.             return;
  897.          }
  898.  
  899.          if (this.gameMode == 49) {
  900.             if (var1 == cheatCode[this.cheatIndex]) {
  901.                if (++this.cheatIndex == cheatCode.length) {
  902.                   Runko.soundSelect();
  903.                   if (cheatEnabled) {
  904.                      cheatEnabled = false;
  905.                      this.cheatIndex = 0;
  906.                      this.numBlocks = 4;
  907.                      this.newGame();
  908.                      return;
  909.                   }
  910.  
  911.                   cheatEnabled = true;
  912.                   this.cheatIndex = 0;
  913.                   this.numBlocks = 6;
  914.                   this.mode(51, 0);
  915.                   this.startsctm = System.currentTimeMillis();
  916.  
  917.                   while(System.currentTimeMillis() - this.startsctm < 3000L) {
  918.                      ((Canvas)this).repaint();
  919.                      ((Canvas)this).serviceRepaints();
  920.                      Thread.yield();
  921.                   }
  922.  
  923.                   this.gLevel = 1;
  924.                   this.newGame();
  925.                   this.mode(69, 0);
  926.                   return;
  927.                }
  928.             } else {
  929.                this.cheatIndex = 0;
  930.             }
  931.  
  932.             if (((Canvas)this).getGameAction(var1) != 1 && ((Canvas)this).getGameAction(var1) != 6) {
  933.                if (((Canvas)this).getGameAction(var1) == 8 || var1 == 53) {
  934.                   Runko.soundSelect();
  935.                   if (this.gLevel == 0) {
  936.                      if (cheatEnabled) {
  937.                         this.gLevel = 1;
  938.                         this.newGame();
  939.                         this.mode(69, 0);
  940.                         return;
  941.                      }
  942.  
  943.                      this.mode(50, 0);
  944.                   } else {
  945.                      this.notifyFromMenu = true;
  946.                      this.runko.showHelp(this);
  947.                   }
  948.  
  949.                   this.gLevel = 0;
  950.                }
  951.             } else {
  952.                Runko.soundMove();
  953.                this.gLevel = 1 - this.gLevel;
  954.             }
  955.          } else if (this.gameMode == 50) {
  956.             if (((Canvas)this).getGameAction(var1) != 1 && ((Canvas)this).getGameAction(var1) != 6) {
  957.                if (((Canvas)this).getGameAction(var1) == 8 || var1 == 53) {
  958.                   MelodyManager.playMelody(6);
  959.                   this.newGame();
  960.                   this.mode(69, 0);
  961.                }
  962.             } else {
  963.                Runko.soundMove();
  964.                this.gLevel = 1 - this.gLevel;
  965.             }
  966.          } else {
  967.             if (!cheatEnabled) {
  968.                if (var1 == cheatCode2[this.cheatIndex]) {
  969.                   if (++this.cheatIndex == cheatCode2.length) {
  970.                      Runko.soundSelect();
  971.                      ++this.lives;
  972.                      this.cheatIndex = 0;
  973.                   }
  974.                } else {
  975.                   this.cheatIndex = 0;
  976.                }
  977.             }
  978.  
  979.             if (((Canvas)this).getGameAction(var1) != 2 && var1 != 52) {
  980.                if (((Canvas)this).getGameAction(var1) == 5 || var1 == 54) {
  981.                   this.keyPressedRight();
  982.                }
  983.             } else {
  984.                this.keyPressedLeft();
  985.             }
  986.          }
  987.       }
  988.  
  989.    }
  990.  
  991.    protected void keyReleased(int var1) {
  992.    }
  993.  
  994.    private void keyPressedLeft() {
  995.       if (this.playerState == 0 && this.playerPos > 0) {
  996.          --this.playerPos;
  997.          this.playerPosCounter = 0;
  998.          if (this.playerPos == 0) {
  999.             this.playerFrame = 3 + random() % 3;
  1000.          } else {
  1001.             this.playerFrame = random() % 3;
  1002.          }
  1003.  
  1004.          this.updatePlayer();
  1005.       }
  1006.  
  1007.    }
  1008.  
  1009.    private void keyPressedRight() {
  1010.       if (this.playerState == 0 && (this.playerPos < this.numBlocks + 1 && this.boxState == 1 || this.playerPos < this.numBlocks)) {
  1011.          ++this.playerPos;
  1012.          this.playerPosCounter = 0;
  1013.          if (this.playerPos == this.numBlocks + 1) {
  1014.             this.playerFrame = random() % 3;
  1015.          } else {
  1016.             this.playerFrame = 3 + random() % 3;
  1017.          }
  1018.  
  1019.          this.updatePlayer();
  1020.       }
  1021.  
  1022.    }
  1023.  
  1024.    private void loadHighScores() {
  1025.       try {
  1026.          byte[] var1 = Jil.loadData("FJungle");
  1027.          ByteArrayInputStream var2 = new ByteArrayInputStream(var1);
  1028.          DataInputStream var3 = new DataInputStream(var2);
  1029.  
  1030.          for(int var4 = 0; var4 < this.hsName.length; ++var4) {
  1031.             for(int var5 = 0; var5 < this.hsName[var4].length; ++var5) {
  1032.                this.hsName[var4][var5] = var3.readUTF();
  1033.                this.hsValue[var4][var5] = var3.readInt();
  1034.             }
  1035.          }
  1036.       } catch (Exception var6) {
  1037.          this.saveHighScores();
  1038.       }
  1039.  
  1040.    }
  1041.  
  1042.    private void saveHighScores() {
  1043.       try {
  1044.          ByteArrayOutputStream var1 = new ByteArrayOutputStream();
  1045.          DataOutputStream var2 = new DataOutputStream(var1);
  1046.  
  1047.          for(int var3 = 0; var3 < this.hsName.length; ++var3) {
  1048.             for(int var4 = 0; var4 < this.hsName[var3].length; ++var4) {
  1049.                var2.writeUTF(this.hsName[var3][var4]);
  1050.                var2.writeInt(this.hsValue[var3][var4]);
  1051.             }
  1052.          }
  1053.  
  1054.          Jil.saveData("FJungle", var1.toByteArray());
  1055.       } catch (Exception var5) {
  1056.       }
  1057.  
  1058.    }
  1059.  
  1060.    private int checkHighScore(int var1) {
  1061.       for(int var2 = 0; var2 < 10; ++var2) {
  1062.          if (var1 > this.hsValue[this.gLevel][var2]) {
  1063.             return var2;
  1064.          }
  1065.       }
  1066.  
  1067.       return -1;
  1068.    }
  1069.  
  1070.    private void updateHighScore(int var1, String var2) {
  1071.       int var3 = this.gLevel;
  1072.       if (cheatEnabled) {
  1073.          var3 = 2;
  1074.       }
  1075.  
  1076.       for(int var4 = 0; var4 < 10; ++var4) {
  1077.          if (var1 > this.hsValue[var3][var4]) {
  1078.             for(int var5 = 9; var5 > var4; --var5) {
  1079.                this.hsName[var3][var5] = this.hsName[var3][var5 - 1];
  1080.                this.hsValue[var3][var5] = this.hsValue[var3][var5 - 1];
  1081.             }
  1082.  
  1083.             this.hsName[var3][var4] = var2;
  1084.             this.hsValue[var3][var4] = var1;
  1085.             System.gc();
  1086.             return;
  1087.          }
  1088.       }
  1089.  
  1090.    }
  1091.  
  1092.    private void updateHighScoreImage(Image var1, int var2, String[] var3, int[] var4) {
  1093.       Graphics var5 = var1.getGraphics();
  1094.       var5.setFont(this.font2);
  1095.       var5.setColor(16777215);
  1096.       var5.fillRect(0, 0, var1.getWidth(), var1.getHeight());
  1097.       var5.setColor(0);
  1098.       if (var2 != 2) {
  1099.          Jil.drawSubImage(this.image[4], 0, 30 + (1 - var2) * 19, 101, 19, var5, (this.width >> 1) - 50, 0);
  1100.       } else {
  1101.          var5.drawString("HARDCORE!", ((Canvas)this).getWidth() >> 1, 5, 17);
  1102.       }
  1103.  
  1104.       var5.setClip(0, 0, var1.getWidth(), var1.getHeight());
  1105.       int var6 = this.font.stringWidth("10.") + 2;
  1106.       int var7 = var1.getWidth() - 8;
  1107.       byte var8 = 24;
  1108.       int var9 = 0;
  1109.  
  1110.       for(int var10 = 2 + var8 + this.font.getBaselinePosition(); var9 < 10; var10 += this.font.getHeight()) {
  1111.          var5.drawString(Integer.toString(var9 + 1) + ".", var6, var10, 72);
  1112.          var5.drawString(var3[var9], var6 + 1, var10, 68);
  1113.          var5.drawString(Integer.toString(var4[var9]), var7, var10, 72);
  1114.          int var11 = var7 - this.font.stringWidth(Integer.toString(var4[var9])) - 2;
  1115.          int var12 = (var6 + 7 + this.font.stringWidth(var3[var9])) / 5 * 5;
  1116.          if (var12 < var11) {
  1117.             while(var12 < var11) {
  1118.                var5.drawLine(var12, var10, var12, var10);
  1119.                var12 += 5;
  1120.             }
  1121.          }
  1122.  
  1123.          ++var9;
  1124.       }
  1125.  
  1126.    }
  1127.  
  1128.    private void drawSubImage(Image var1, int var2, int var3, int var4, int var5, Graphics var6, int var7, int var8) {
  1129.       if ((var8 >= 0 || var8 + var5 > 0) && var8 < this.height) {
  1130.          if (var7 < 0) {
  1131.             var2 -= var7;
  1132.             var4 += var7;
  1133.             var7 = 0;
  1134.          } else {
  1135.             if (var7 > this.width) {
  1136.                return;
  1137.             }
  1138.  
  1139.             if (var7 + var4 > this.width) {
  1140.                var4 -= var4 + var7 - this.width;
  1141.                if (var4 <= 0) {
  1142.                   return;
  1143.                }
  1144.             }
  1145.          }
  1146.  
  1147.          if (var8 < 0) {
  1148.             var3 -= var8;
  1149.             var5 += var8;
  1150.             var8 = 0;
  1151.          } else if (var5 > this.height) {
  1152.             var5 = this.height;
  1153.          }
  1154.  
  1155.          Jil.drawSubImage(var1, var2, var3, var4, var5, var6, var7, var8);
  1156.       }
  1157.    }
  1158. }
  1159.